package org.ns.longhttp.selector.requestmapper;

import org.ns.longhttp.wrapper.GetRequestWrapper;

public class QueueEntryWrapper {

    private GetRequestWrapper requestWrapper;
    private long invalidTime; // 失效的时间


    public QueueEntryWrapper(GetRequestWrapper requestWrapper, long invalidTime) {
        this.requestWrapper = requestWrapper;
        this.invalidTime = invalidTime;

    }

    public GetRequestWrapper getRequestWrapper() {
        return requestWrapper;
    }

    public long getInvalidTime() {
        return invalidTime;
    }

    /**
     * 是否失效
     * @return
     */
    public boolean isInvalid() {
        long currentTime = System.currentTimeMillis();
        return currentTime > invalidTime || requestWrapper.isInvalid();
    }

    public void close() {
        requestWrapper.write();
    }

}
